package com.jnsw.testkotlin;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

import com.jnsw.testkotlin.utils.FileUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class FileUploadActivity extends AppCompatActivity {

    ProgressBar pb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_file_upload);




        pb = (ProgressBar) findViewById(R.id.progressBar);

        Button btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
//                    FileUtil.uploadFile("/sdcard/download/appcenter/apk/com.meizu.mstore_0.apk","http://10.80.5.247:8087/OAinterface/FileUpload");
                    FileUtil.uploadFile("/sdcard/download/browser/gifnv.gif","http://10.80.5.247:8087/OAinterface/FileUpload");
//                    FileUtil.uploadFile("/sdcard/download/开发外卖.ppt","http://10.80.5.247:8087/OAinterface/FileUpload");
//                    FileUtil.uploadFile("/sdcard/download/外卖数据交互.mp4", "http://10.80.5.247:8087/OAinterface/FileUpload");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });


        EventBus.getDefault().register(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN,sticky = true) //在ui线程执行
    public void Onreceive(final int count) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Log.d("jindu",count +"");
                System.out.println(count);
                pb.setProgress(count);
            }
        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);

    }
}
